<template>
  <div class="stepPre">
    <div class="logoutDiv">
      <div class="subDiv">
        <el-button v-for="(item) in subProcessList" :key="item.processId"
          :type="statusfun(curProProcess.processId, item)">{{ item.processName }}</el-button>
      </div>
      <div style="display: flex;">
        <div style="margin-right: 10px;line-height: 40px;">
          当前登录人：<span>{{
            (currentUser.length >
              10 ?
              currentUser.slice(0, 10) + '…' : currentUser) }}</span></div>
        <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
          <div class="avatar-wrapper">
            <!-- <img :src="avatar" class="user-avatar" /> -->
            <i class="el-icon-more" style="font-size: 28px;" />
          </div>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item @click.native="logout">
              <span>退出登录</span>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>

    <!-- 开工前准备页面 -->
    <!-- style="background-color: rgb(54,169,206);" -->

    <el-steps simple class="step_div">
      <el-step v-for="(item) in routeList" :key="item.processCode" :title="item.processName" icon="false"
        :status="statusfun(curProProcess.processId, item)"></el-step>
    </el-steps>
    <div class="contentBox">
      <!-- <div class="contentDiv"> -->
      <el-row>
        <el-col :span="5" class="imgDiv">
          <span class="spanTitle">工单编号：</span>
          <span class="spanText">{{ this.orderDetail.workorderCode }}</span>
        </el-col>
        <el-col :span="5" class="imgDiv">
          <span class="spanTitle">产品编号：</span>
          <span class="spanText">{{ this.orderDetail.productCode }}</span>
        </el-col>
        <el-col :span="5" class="imgDiv">
          <span class="spanTitle">产品名称：</span>
          <span class="spanText">{{ this.orderDetail.productName }}</span>
        </el-col>
        <el-col :span="8" class="imgDiv">
          <span class="spanTitle">规格型号：</span>
          <span class="spanText">{{ this.orderDetail.productSpc }}</span>
        </el-col>
      </el-row>
      <!-- </div> -->
      <el-row>
        <el-col :span="5" class="imgDiv">
          <span class="spanTitle">类型：</span>
          <span class="spanText">
            {{ this.orderDetail.orderType == 0 ? "未知" : this.orderDetail.orderType == 1 ?
              "普通生产" : this.orderDetail.orderType == 2 ? "返工生产" : this.orderDetail.orderType == 3 ? "样机生产" : "--" }}
          </span>
        </el-col>
        <el-col :span="5" class="imgDiv">
          <span class="spanTitle">数量：</span>
          <!-- {{ this.orderDetail.unitOfMeasure }} -->
          <span class="spanText">{{ this.orderDetail.quantity }}</span>
        </el-col>
        <el-col :span="5" class="imgDiv">
          <span class="spanTitle">开始时间：</span>
          <span class="spanText">{{ this.orderDetail.actualStartTime }} </span>
          <!-- ~ {{ this.orderDetail.actualFinisihTime }} -->
        </el-col>
        <el-col :span="5" class="imgDiv">
          <span class="spanTitle">sn码：</span>
          <!-- {{ this.orderDetail.unitOfMeasure }} -->
          <span class="spanText">{{ snCode }}</span>
        </el-col>
      </el-row>
      <!-- <div class="contentDiv"></div> -->
    </div>
  </div>
</template>

<script>
import { proWorkOrderlist, headerInfo } from "@/api/apppro/index";
import { mapGetters } from "vuex";
export default {
  name: "stepsItema",
  data() {
    return {
      routeList: [],
      orderDetail: {},
      processName: null,
      subProcessList: [],
      curProProcess: [],
      form: {},
      currentUser: this.$store.state.user.name,//当前登录人
    };
  },
  props: {
    changeObj: Function,
    snCode: String,
  },
  computed: {
    ...mapGetters(["sidebar", "avatar", "device"])
  },
  created() {
    console.log(
      this.$route.query,
      "==============this.$route.query =========="
    );
  },
  methods: {
    clearData() {
      this.routeList = [],
        this.orderDetail = {},
        this.processName = null,
        this.subProcessList = [],
        this.curProProcess = [],
        this.form = {}
    },
    statusfun(i, item, type) {
      if (i == item.processId) {
        this.orderDetail.processName = item.processName;
        this.orderDetail.processCode = item.processCode;
        this.orderDetail.processId = item.processId;
        return "success";
      }
      return "process";
    },
    getList(snCode) {
      let param = {
        snCode: snCode
      }
      headerInfo(param).then(res => {
        console.log(res, "==========res===========");
        // debugger
        if (res.code == 200) {
          const { proWorkorder = {}, mdWorkstation = {} } = res.data;
          this.orderDetail = { ...proWorkorder, ...mdWorkstation } || {};
          this.routeList = res.data?.finalProcessList || [];
          this.subProcessList = res.data?.subProcessList;
          this.curProProcess = res.data.curProProcess;
          this.changeObj(this.orderDetail);
        }
      });
    },
    async logout() {
      this.$confirm("确定注销并退出系统吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$store.dispatch("LogOut").then(() => {
            location.href = "/index";
          });
        })
        .catch(() => { });
    },


  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.stepPre ::v-deep .el-icon-check::before {
  // display: none !important;
  content: "";
}

.stepPre ::v-deep .el-step__title {
  white-space: nowrap;
}

.stepPre ::v-deep .el-step.is-simple .el-step__head {
  width: 0px;
}

.logoutDiv {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.subDiv {
  margin-bottom: 15px;

  button {
    margin: 0 10px;
    font-size: 18px;
  }
}

.contentBox {
  margin-top: 10px;
  background-color: #f5f7fa;
  padding: 10px 20px;
  line-height: 36px;

  .contentDiv {
    display: flex;
    // justify-content: left;
    align-items: center;
    // flex-wrap: wrap;
    line-height: 36px;
    font-size: 16px;

    span:nth-child(n) {
      width: 5%;
      white-space: nowrap;
    }

    span:nth-child(2n) {
      width: 16%;
      white-space: nowrap;
    }
  }
}

.right-menu-item {
  display: inline-block;
  padding: 0 8px;
  height: 100%;
  font-size: 18px;
  color: #5a5e66;
  vertical-align: text-bottom;

  &.hover-effect {
    cursor: pointer;
    transition: background 0.3s;

    &:hover {
      background: rgba(0, 0, 0, 0.025);
    }
  }
}

.avatar-container {
  margin-right: 30px;

  .avatar-wrapper {
    margin-top: 5px;
    position: relative;

    .user-avatar {
      cursor: pointer;
      width: 40px;
      height: 40px;
      border-radius: 10px;
    }

    .el-icon-caret-bottom {
      cursor: pointer;
      position: absolute;
      right: -20px;
      top: 25px;
      font-size: 12px;
    }
  }
}
</style>